# Maintainer: Andrew Sun <adsun701@gmail.com>

_realname=mono-basic
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=4.8
pkgrel=1
pkgdesc="Mono Visual Basic.NET compiler (mingw-w64)"
arch=('any')
url="https://www.mono-project.com/"
license=('LGPL')
depends=("${MINGW_PACKAGE_PREFIX}-mono")
source=(#"${_realname}-${pkgver}.tar.xz"::"https://download.mono-project.com/sources/${_realname}/${_realname}-${pkgver}.tar.bz2"
        "${_realname}-${pkgver}::git+https://github.com/mono/mono-basic.git#commit=e31cb702937a0adcc853250a0989c5f43565f9b8"
        "0001-mono-basic-4.6-fix-slash-vs-hyphen.patch")
sha256sums=('SKIP'
            '8406a7e478b62c2d24000b4da3398a5c946b09cda1d61637c520faad9b993ec6')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -Np1 -i "${srcdir}/0001-mono-basic-4.6-fix-slash-vs-hyphen.patch"
}

build() {
  # get rid of that .wapi errors
  export MONO_SHARED_DIR="${srcdir}/weird-${CARCH}"
  mkdir -p "${MONO_SHARED_DIR}"

  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  cp -Rf "${srcdir}"/${_realname}-${pkgver} "${srcdir}"/build-${CARCH}
  cd "${srcdir}"/build-${CARCH}

  CC=${MINGW_PREFIX}/bin/gcc.exe \
  CSC=${MINGW_PREFIX}/bin/mcs \
  ./configure \
    --prefix=${MINGW_PREFIX}

  make
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make DESTDIR="${pkgdir}" install

  sed -e "s|/sdkpath|-sdkpath|g" -i "${pkgdir}${MINGW_PREFIX}/bin/vbnc2"
}
